package day01;
import java.util.Arrays;
import  java.util.Random;
import java.util.Scanner;
/**
 * 随机输出单词，用户输入单词的中文，
 * 对比是否正确
 * 正确返回true
 * 错误返回false
 */


import java.util.*;

/**
 * @author lxg
 * @version 1.0
 * @title demo
 * @description: 接受用户的本日单词，随机输出
 * @Date 2022/8/25
 * @since
 */
public class Word {
    public static void main(String[] args) {
        //定义一个HashMap存储单词    字典
        HashMap<String,String> map = new HashMap<>();
        //定义一个Scanner对象接受用户的输入
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入今日待背诵单词(q为退出)");
        String words = "";
        String paraphrase;  //中文释义
        while (!words.equals("q")){
            System.out.print("输入单词:");
            words = sc.nextLine();
            if (words.equals("q")){
                break;
            }
            System.out.print("输入释义:");
            paraphrase = sc.nextLine();
            map.put(words,paraphrase);
        }
        System.out.println("输入完毕...");
        System.out.println("开始单词背诵...");
        //获取英语单词，并打乱顺序
        ArrayList<String> sets = new ArrayList<>(map.keySet());
        Collections.shuffle(sets); //打乱
        Iterator it = sets.iterator();  //获取集合的迭代器，放在it中
        int i = 1;int score = 0;
//        while(true){
            while (it.hasNext()){
//        while (true){
                String key = (String) it.next();
                System.out.println("第"+i+"个单词:"+key);
                System.out.print("请输入释义:");
                String par = sc.nextLine();
                if (map.get(key).contains(par)){
                    System.out.println("回答正确!");
                    score++;
                }else{
                    System.out.println("真失败,回答错误");
                }
                i++;
            }
//
//        }
//        System.out.println("恭喜你,背诵成功的单词数为:"+score);
    }
}



/*
public class Word {
    public static void main(String[] args) {
//       String[] word = {"","","","","","","","","","","","","","","","","",""};
//       String[] chinese = {"","","","","","","","","","","","","","","","","",""};
        */
/**
         * 单词数组
         *//*

        String[] word= {"collection","lise","empty","clear","contains","remove","retain","iterator","reverse","compare","link","linkedlist"};
        */
/**
         * 中文数组
         *//*

        String[] chinese = {"集合","列表","空","清空","包含","删除","保留","迭代","反转","比较","链接","链表"};
        int cards=0;
        Random random = new Random();
        for(int i =word.length-1;i>=1;i--)
        {
            //打乱单词数组
            int j = random.nextInt(i);
            String t = word[i];
            word[i] = word[j];
            word[j] = t ;
            //中文数组一起打乱
           t = chinese[i];
            chinese[i] = chinese[j];
            chinese[j] = t ;
        }
        //测试数组打乱
        System.out.println(Arrays.toString(word));
        System.out.println(Arrays.toString(chinese));
        //创建随机的单词
        int w =random.nextInt(word.length);
        String str =  word[w];
        String ch =  chinese[w];
        //输出随机的一个单词
        System.out.println("word   :"+(w+1)+":"+str);
//        System.out.println("chinese:"+(w+1)+":"+ch);
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入对应中文单词：");
        String year = scanner.nextLine();
        //判断输入的中文是否与单词匹配
        */
/*
        * 怎么将输入的中文和对应单词相比？
        * *//*

        System.out.println("你输入的是："+year);
    }
}
*/
